package com.cloudwise.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloudwise.dao.TesterDao;
import com.cloudwise.entity.Tester;
import com.cloudwise.service.TesterService;
import lombok.Data;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * (Tester)表服务实现类
 *
 * @author makejava
 * @since 2021-11-25 09:42:21
 */
@Service("testerService")
public class TesterServiceImpl extends ServiceImpl<TesterDao, Tester> implements TesterService {

    @Override
    public boolean login(Tester tester){
        QueryWrapper queryWrapper = new QueryWrapper<>().eq("tester_phone", tester.getTesterPhone()).eq("tester_name", tester.getTesterName());
        Tester t = this.getOne(queryWrapper);
        if (t == null){
            return false;
        }else {
            tester.setTesterId(t.getTesterId());
            tester.setTestTime(t.getTestTime());
            return true;
        }
    }
    @Override
    public boolean phoneExist(String testerPhone){
        QueryWrapper queryWrapper = new QueryWrapper<>().eq("tester_phone", testerPhone);
        Tester tester = this.getOne(queryWrapper);
        if (tester == null){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public String findTesterNameById(Integer testerId) {
        Tester tester = this.getById(testerId);
        if (tester == null){
            return null;
        }
        return tester.getTesterName();
    }

    @Override
    public String findTestTimeById(Integer testerId) {
        Tester tester = this.getById(testerId);
        if (tester == null){
            return null;
        }
        Date date = tester.getTestTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }
}

